package com.mikao.dao;

import com.mikao.entity.Goods;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * @author KennyDavid
 */
public interface GoodsDao extends JpaRepository<Goods, Long>, JpaSpecificationExecutor {

    /**
     * 批量改变文章状态
     *
     * @param ids    id
     * @param status 状态
     */
    @Modifying
    @Query("update Goods a set a.status=?2 where a.id in (?1)")
    void updateGoodsStatus(List<Long> ids, Boolean status);

    /**
     * 查询折扣商品
     *
     * @param type 种类
     * @return list
     */
    List<Goods> findAllByType(Integer type);

    @Query("select m from Goods m where m.type=4 and m.introduce like concat('%',?1,'%') ")
    List<Goods> findAllByTypeLike(String name);
}
